<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<base href='<?php echo base_url()?>'>
<link rel="stylesheet" type="text/css" href="public/common/css/common.css"/>
<link rel="stylesheet" type="text/css" href="public/admin/css/admin.css"/>
<script src="public/common/js/jquery.js"></script>
<script>
$(function(){
	$('select[name="category_id"]').val("<?php echo $this->input->get('category_id')?>")
})
function select_all()
{
	$('.table').find('input:checkbox').attr('checked',true);
}
function select_other()
{
	check_obj = $('.table').find('input:checked');
	$('.table').find('input:checkbox').attr('checked',true);
	check_obj.attr('checked',false);
}
function del(obj,article_id)
{
	$.post('<?php echo site_url("admin/article/delete_article")?>',{article_id:article_id},function(result){
		if(result == '1')
		{
			$(obj).parent().parent().remove();
		}else{
			alert('删除失败！');
		}
	});	
}
function delete_article(obj,article_id)
{
	if(confirm('确定要删除吗？删除后不可恢复！'))
	{
		del(obj,article_id);	
	}
}
function delete_select_article()
{
	if(confirm('确定删除所选吗？删除后不可恢复！'))
	{
		$('input:checked').each(function(){
			del(this,$(this).val());
		});
	}	
}
</script>
</head>
<body>
	<div class="body">
    	<?php echo $this->position->get_position();?>
        <div class="body_center">
        	<form action="<?php echo site_url('admin/article/index')?>" method="get">
                <div class="list_sl_btn">
                    <ul>
                    <li>
                        <select name="category_id" style="width:200px;margin-top:2px;">
                                <?php if($category_tree):?>
                                    <option value="0">请选择分类</option>
                                    <?php echo $category_tree;?>
                                <?php else:?>
                                    <option value='0'>没有对应分类</option>
                                <?php endif;?>
                        </select>
                    </li>
                    <li>
                        关键字：<input type="text" name='key_words' />
                    </li>
                    <li>
                        <input type="submit" value='搜索' class='submit' />
                    </li>
                    </ul>
                </div>
            </form>
            	<table class="table">
                	<tr><th>选择</th><th>文章标题</th><th>所属栏目</th><th>发布人</th><th>点击</th><th>添加时间</th><th>操作</th></tr>
                    	<?php if(empty($article)):?>
                        	<tr><td colspan="7" align="center">没有任何数据</td></tr>
                        <?php else:?>
							 <?php foreach($article->result() as $value):?>
                            <tr>
                                <td align="center"><input type="checkbox" value="<?php echo $value->article_id?>"></td>
                                <td><?php echo substr($value->article_title,0,60)?></td>
                                <td align="center">
                                     <?php $category = $this->cic_model->get_one('category',array('category_id'=>$value->category_id))?>
                                     <?php echo $category->category_name;?>
                                </td>
                                <td align="center"><?php echo $value->article_user_add?></td>
                                <td align="center"><?php echo $value->article_hits?></td>
                                <td align="center"><?php echo date('Y-m-d',$value->article_create_time)?></td>
                                <td align="center"><a href="<?php echo site_url('admin/article/article_edit/'.$value->article_id)?>">修改</a> | <a href="javascript:void(0)" onclick="delete_article(this,<?php echo $value->article_id?>)">删除</a></td>
                            </tr>
                            <?php endforeach;?>
                        <?php endif;?> 	
                     <tr>
                         <td colspan="7" align="right">
                            <input type=button class="submit" value="全选" onclick="select_all()"> 
                            <input type=button onclick="select_other()" class="submit" value="反选"> 
                            <input type=button value="删除" class="button" onclick="delete_select_article()">
                         </td>
               		 </tr>
                </table>
        </div>
        <div class="page"><?php echo $page?></div>
    </div>
</body>
</html>